<template>
    <div class="bc-container">
        <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/AIAnalysis' }">AI智能分析</el-breadcrumb-item>
            <el-breadcrumb-item :to="{ path: '/ReportType' }">选择报告类型</el-breadcrumb-item>
            <el-breadcrumb-item class="bc-item">行业分析预览</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="report-type">
        <div class="report-header">
            <h3>选择报告类型</h3>
            <span>AI大模型算法赋能，高效分析招商项目价值</span>
        </div>
        <div class="rc-content">
            <div class="type-list">
                <div class="item" :class="{ 'active' : index+1 == permissonPDF  }" v-for="(item, index) in list" :key="index">
                    <div class="item-header">
                        <img :src="item.icon" alt="">
                        <h3>{{ item.title }}</h3>
                    </div>
                    <div class="item-body">
                        <ul>
                            <li v-for="(childItem, childIndex) in item.content" :key="childIndex">{{ childItem }}</li>
                        </ul>
                    </div>
                    <div class="item-footer">
                        <div class="btn" @click="onPreView(item.id)">行业分析预览</div>
                    </div>
                </div>
            </div>
            <div class="pdf-report">
                <el-scrollbar height="100%">
                    <vue-pdf-embed :source="pdfState.url" v-for="page in pdfState.numPages" :page="page" :key="page"
                        textLayer ref="vuePdfRef" />
                </el-scrollbar>
                <div class="btns">
                    <el-button>关闭预览</el-button>
                    <el-button type="primary" @click="onPDFDownload">导出报告</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue"
import AI1 from "../../assets/images/ai-1.png"
import AI2 from "../../assets/images/ai-2.png"
import AI3 from "../../assets/images/ai-3.png"
import { useRoute } from "vue-router"

// 引入PDF
import VuePdfEmbed from "vue-pdf-embed";
import { createLoadingTask } from "vue3-pdfjs/esm";

// 文件路径
import pdfUrl from '../../assets/pdf/explemnt.pdf';

const route = useRoute()

// 权限
const permissonPDF = ref(0)

const list = [
    {
        id:1,
        icon: AI1,
        title: "行业智能研判",
        content: ["行业概括分析", "产业链上中下游分析", "产业市场规模分析", "发展趋势分析", "投资决策建议", "代表企业分析", "行业政策分析", "技术创新分析", "技术创新分析"]
    },
    {
        id:2,
        icon: AI2,
        title: "企业竞争力分析",
        content: ["企业基本信息", "主营产品/服务", "所在行业竞争格局", "企业产品竞争力", "企业创新能力", "企业标准制定"]
    },
    {
        id:3,
        icon: AI3,
        title: "产业市场规模分析",
        content: ["产品应用领域", "产品市场规模", "产品市场驱动因素", "产品未来市场空间"]
    }
]

const vuePdfRef = ref(null);
const pdfState = reactive({
    // url: "https://store.industrychain.online/zhaoshang/explemnt.pdf",
    url: pdfUrl,
    // 当前页
    pageNum: 1,
    // 总页数
    numPages: 1,
})

onMounted(() => {
    const loadingTask = createLoadingTask(pdfState.url);
    loadingTask.promise.then((pdf) => {
        // 获取页面总页数
        pdfState.numPages = pdf.numPages;
    });
});

onMounted(() =>{
    permissonPDF.value = route.params.id
})

const onPreView = (id) =>{
    permissonPDF.value = id
    console.log("更换PDF");
}


function getPDFFileName() {
    const last_index = pdfState.url.lastIndexOf('/');
    return pdfState.url.slice(last_index + 1);
}

const onPDFDownload = () => {
    vuePdfRef.value[0].download(getPDFFileName());
}


</script>

<style lang="less" scoped>
.report-type {
    padding: 20px 50px;
    background: #fff;

    // box-shadow: 0 5px 10px rgba(0, 0, 0, .1);
    .report-header {
        h3 {
            font-size: 28px;
            color: #373737;
        }

        span {
            display: block;
            font-size: 16px;
            margin: 15px 0;
        }
    }

    .rc-content {
        display: flex;

        .type-list {
            flex: 1;
            margin: 10px 0;
            margin-right: 50px;

            .item {
                text-align: center;
                box-shadow: 0px 3px 6px 0px rgba(72, 94, 132, 0.2);
                display: flex;
                flex-direction: column;
                background: linear-gradient(#f0f4fc, #ffffff);
                margin: 30px 10px;
                margin-right: 40px;
                border: 1px solid transparent;
                border-radius: 10px;

                .item-header {
                    background-size: cover;
                    display: flex;
                    padding: 5px;
                    align-items: center;

                    img {
                        width: 40px;
                        height: 40px;
                        padding: 10px 20px;
                    }

                    h3 {
                        font-size: 20px;
                        color: #000000;
                        padding: 10px 0;
                    }
                }

                .item-body {
                    flex: 1;
                    padding: 0 20px;

                    ul {
                        overflow: hidden;
                        clear: both;

                        li {
                            float: left;
                            height: 35px;
                            line-height: 35px;
                            font-size: 16px;
                            color: #000000;
                            text-overflow: ellipsis;
                            overflow: hidden;
                            word-break: break-all;
                            white-space: nowrap;
                            margin: 0 10px;
                        }

                        .liRow {
                            width: 100%;
                            float: none;
                        }
                    }
                }

                .item-footer {
                    padding: 10px 0;
                    display: flex;
                    justify-content: flex-end;
                    align-items: center;
                    margin-right: 20px;

                    .btn {
                        background-color: #536EF7;
                        color: #fff;
                        width: 160px;
                        height: 40px;
                        line-height: 40px;
                        cursor: pointer;
                        border-radius: 5px;
                    }
                }
            }
            .item.active{
                border: 1px solid #496bff;
            }
        }

        .pdf-report {
            flex: 1;
            padding: 10px;
            box-shadow: -1px -1px 15px rgba(0, 0, 0, .1);
            background: linear-gradient(#f0f4fc, #ffffff);

            :deep(.el-scrollbar) {
                height: 650px;
            }

            .btns {
                margin-top: 10px;
                display: flex;
                justify-content: space-evenly;
            }
        }
    }
}
</style>